import {Component, OnInit, EventEmitter, Input, Output, Injector} from '@angular/core';

import {EmployeeServiceSvr} from '../../../services/employee.service';
import {CoreComponent} from 'pengesoft-ng-lib';

export interface Data {
  id: number;
  skay: number;
  name: string;
  posting: string;
  department: string;
  jobnumber: number;
  headImg: string;
}


@Component({
  selector: 'app-filestable',
  templateUrl: './filestable.component.html',
  styleUrls: ['./filestable.component.less']
})
export class FilestableComponent extends CoreComponent implements OnInit {

  @Output() cancelFileShowModal = new EventEmitter();
  @Input() enterFilesShow: {};



  loading = false;
  // tslint:disable-next-line:max-line-length
  listOfData: { skay: number; jobnumber: any; phone: any; sex: string; name: any; id: any; state: any; posting: any; department: any; age: any }[] = [];
  setOfCheckedId = new Set<number>();
  // 传给详情的值
  // tslint:disable-next-line:max-line-length
  sendEmployee: { EmergencyContact: string; ExtAttr: string; Sex: number; StateId: string; JobName: string; CardAddress: string; CardNum: string; EmployeeDay: number; Birth: Date | string; Politic: string; Name: string; EmergencyPeople: string; CardType: string; Phone: string; DeptName: string; ArchivesFile: string; Age: number; JobId: string; StudyMajor: string; NativePlace: string; IDCard: string; IDPlace: string; NowPlace: string; EducationLevel: string; ArchivesNum: string; Id: string; GraduatedSchool: string; GraduatedTime: Date | string; HouseholdType: string };

  constructor(private injector: Injector,
              private employSvr: EmployeeServiceSvr) {
    super(injector);
  }

  ngOnInit(): void {
    this.queryEmployee();
  }

  // 查询所有员工花名册/档案
  queryEmployee(): any {
    this.employSvr.myGetAllEmployDto().then(res => {
      this.listOfData = res.map((items, index) => {
        const sex = items.Employee.sex === 0 ? '男' : '女';
        return {
          id: items.Employee.Id,
          skay: index + 1,
          posting: items.JobName,
          department: items.DeptName,
          jobnumber: items.Employee.Id,
          age: items.Employee.Age,
          sex,
          phone: items.Employee.Phone,
          state: items.Employee.StateId,
          name: items.Employee.Name
        };

      });
      return this.listOfData;
    });
  }

  // 点击进去
  enterFiles(data: Data): void {
    window.sessionStorage.setItem('sendEnterFilesID', String(data.id));
    window.sessionStorage.setItem('sendEnterFilesName', String(data.name));
    this.cancelFileShowModal.emit();
    this.employSvr.getArchivesByEmpId(String(data.id)).then(res => {
      this.sendEmployee = this.dealData(res);
      window.sessionStorage.setItem('sendEnterEmployee', JSON.stringify(this.sendEmployee));
    });
  }

  // 通过个人id查询个人详细信息
  getDetailImformation(id): void {
    this.employSvr.getArchivesByEmpId(id).then(res => {
      this.sendEmployee = this.dealData(res);
      window.sessionStorage.setItem('sendEnterEmployee', JSON.stringify(this.sendEmployee));
    });
  }

  // 数据的处理
  dealData(res): any{
    return {
      DeptName: res.EmployeeDto.DeptName,
      Age: res.EmployeeDto.Employee.Age,
      ArchivesFile: res.EmployeeDto.Employee.ArchivesFile,
      ArchivesNum: res.EmployeeDto.Employee.ArchivesNum,
      Birth: res.EmployeeDto.Employee.Birth,
      CardAddress: res.EmployeeDto.Employee.CardAddress,
      CardNum: res.EmployeeDto.Employee.CardNum,
      CardType: res.EmployeeDto.Employee.CardType,
      EducationLevel: res.EmployeeDto.Employee.EducationLevel,
      EmergencyContact: res.EmployeeDto.Employee.EmergencyContact,
      EmergencyPeople: res.EmployeeDto.Employee.EmergencyPeople,
      EmployeeDay: res.EmployeeDto.Employee.EmployeeDay,
      ExtAttr: res.EmployeeDto.Employee.ExtAttr,
      GraduatedSchool: res.EmployeeDto.Employee.GraduatedSchool,
      GraduatedTime: res.EmployeeDto.Employee.GraduatedTime,
      HouseholdType: res.EmployeeDto.Employee.HouseholdType,
      IDCard: res.EmployeeDto.Employee.IDCard,
      IDPlace: res.EmployeeDto.Employee.IDPlace,
      Id: res.EmployeeDto.Employee.Id,
      JobId: res.EmployeeDto.Employee.JobId,
      Name: res.EmployeeDto.Employee.Name,
      NativePlace: res.EmployeeDto.Employee.NativePlace,
      NowPlace: res.EmployeeDto.Employee.NowPlace,
      Phone: res.EmployeeDto.Employee.Phone,
      Politic: res.EmployeeDto.Employee.Politic,
      Sex: res.EmployeeDto.Employee.Sex,
      StateId: res.EmployeeDto.Employee.StateId,
      StudyMajor: res.EmployeeDto.Employee.StudyMajor,
      JobName: res.EmployeeDto.JobName
    };
  }

}
